﻿using huaxin_core;
using huaxin_Model;
using Senparc.Weixin.MP;
using Senparc.Weixin.MP.TenPayLibV3;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace huaxin_luckdraw.WxPayHelp
{

    /// <summary>
    /// 统一订单帮助类
    /// </summary>
    public class UnifiedOrder
    {

        /// <summary>
        /// 接收财付通通知的URL  http://weixin.liaowa365.com/NotifyPay/PayNotifyUrl
        /// </summary>
        private static readonly string _notify= "http://luck.sjs361.com/NotifyPay/PayNotifyUrl";

        public static TenPayV3UnifiedorderRequestData CreatePayModel(huaxin_order order,string productName)
        {

            string nonceStr = TenPayV3Util.GetNoncestr();
            int totalFee=Convert.ToInt32((order.PaymentAmount * 100));

            TenPayV3Type tradeType = TenPayV3Type.NATIVE;
            if (!string.IsNullOrEmpty(order.OpenId))
            {
                tradeType = TenPayV3Type.JSAPI;
            }



            return new TenPayV3UnifiedorderRequestData(
                WxConfig.AppId,
                WxConfig.MchId,
                productName,
                order.OrderId,
                totalFee,
                order.Ip,
                _notify,
                tradeType,
                order.OpenId,
                WxConfig.Key,
                nonceStr,
                "",
                order.TimeStart,
                order.TimeExpire,
                order.Remark,
                "",
                "CNY",
                "",
                order.ProductId,
                false
                );
        }

        /// <summary>
        /// 统一支付接口
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public static UnifiedorderResult GetSendOrderResult(TenPayV3UnifiedorderRequestData para)
        {
            return TenPayV3.Unifiedorder(para);
        }

    }
}